﻿#include "settingdialog.h"
#include "ui_settingdialog.h"

#include <QtWidgets>

SettingDialog::SettingDialog(const QList<Setting>& list, QWidget* parent)
    : QDialog(parent), ui(new Ui::SettingDialog)
{
    ui->setupUi(this);
    setFixedSize(this->width(), this->height());
    setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);

    connect(ui->okButton, &QAbstractButton::clicked, this, &QDialog::accept);
    connect(ui->cancelButton, &QAbstractButton::clicked, this, &QDialog::reject);

    ui->timeEdit_0->setTime(QTime(list[0].period,0));
    ui->volume_lineEdit_0->setText(QString::number(list[0].volume));
    ui->voltMin_lineEdit_0->setText(QString::number(list[0].volt_min));
    ui->curMax_lineEdit_0->setText(QString::number(list[0].cur_max));

    ui->timeEdit_1->setTime(QTime(list[1].period,0));
    ui->volume_lineEdit_1->setText(QString::number(list[1].volume));
    ui->voltMin_lineEdit_1->setText(QString::number(list[1].volt_min));
    ui->curMax_lineEdit_1->setText(QString::number(list[1].cur_max));

    ui->timeEdit_2->setTime(QTime(list[2].period,0));
    ui->volume_lineEdit_2->setText(QString::number(list[2].volume));
    ui->voltMin_lineEdit_2->setText(QString::number(list[2].volt_min));
    ui->curMax_lineEdit_2->setText(QString::number(list[2].cur_max));

    ui->timeEdit_3->setTime(QTime(list[3].period,0));
    ui->volume_lineEdit_3->setText(QString::number(list[3].volume));
    ui->voltMin_lineEdit_3->setText(QString::number(list[3].volt_min));
    ui->curMax_lineEdit_3->setText(QString::number(list[3].cur_max));

    setWindowTitle(QStringLiteral("注脂器设置"));
}

SettingDialog::~SettingDialog()
{
    delete ui;
}

QList<Setting> SettingDialog::getSettings()
{
    QList<Setting> list;
    list.append({ui->timeEdit_0->time().hour(),ui->volume_lineEdit_0->text().toInt(), ui->voltMin_lineEdit_0->text().toInt(), ui->curMax_lineEdit_0->text().toInt()});
    list.append({ui->timeEdit_1->time().hour(),ui->volume_lineEdit_1->text().toInt(), ui->voltMin_lineEdit_1->text().toInt(), ui->curMax_lineEdit_1->text().toInt()});
    list.append({ui->timeEdit_2->time().hour(),ui->volume_lineEdit_2->text().toInt(), ui->voltMin_lineEdit_2->text().toInt(), ui->curMax_lineEdit_2->text().toInt()});
    list.append({ui->timeEdit_3->time().hour(),ui->volume_lineEdit_3->text().toInt(), ui->voltMin_lineEdit_3->text().toInt(), ui->curMax_lineEdit_3->text().toInt()});
    return list;
}
